<%@page import="java.util.List"%>
<%@page import="javax.jdo.Query"%>
<%@page import="org.passout.projecter.model.PMF"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="org.passout.projecter.model.test.Chapter"%>
<%@page import="org.passout.projecter.model.test.Book"%>
<%@page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@page import="com.google.appengine.api.users.User"%>
<%@page import="com.google.appengine.api.users.UserService"%>
<html>
<body>
<%
  Book b = new Book();
  b.setTitle("JDO 4eva");
  Chapter c1 = new Chapter();
  c1.setTitle("Intro");
  c1.setNumPages(10);
  b.getChapters().add(c1);
  Chapter c2 = new Chapter();
  c2.setTitle("Configuration");
  c2.setNumPages(9);
  b.getChapters().add(c2);

  PersistenceManager pm = PMF.get().getPersistenceManager();
  pm.currentTransaction().begin();
  try {
      pm.makePersistent(b);
      pm.currentTransaction().commit();
  } finally {
      if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
      }
  }
  Query q = pm.newQuery(Chapter.class);
  List<Chapter> result = (List<Chapter>) q.execute();
  for(Chapter c : result){
	  %>
	  <%= c.getBook() %>
	  <%
  }
  %>
</body>
</html>
